package bcit.nxt.mission;

// TurtleSquare.java
import gin.and.tonic.*;
import lejos.nxt.Button;
import lejos.nxt.ButtonListener;

public class ReMove implements UltrasonicListener, TouchListener, ButtonListener
{

    private DragonRobot robot = new DragonRobot();
    private boolean ReachSpot = false;
    Motor arm;

    ReMove()
    {
        UltrasonicSensor us = new UltrasonicSensor(SensorPort.S1);
        TouchSensor ts = new TouchSensor(SensorPort.S2);
        arm = new Motor(MotorPort.A);
        robot.addPart(us);
        robot.addPart(ts);
        us.addUltrasonicListener(this, 7);
        ts.addTouchListener(this);
        robot.addPart(arm);
        arm.setSpeed(20);
        //robot.forward(300);
        robot.getGear().setSpeed(80);
        robot.getGear().forward();


    }

    public void far(SensorPort port, int level)
    {
    }

    public void near(SensorPort port, int level)
    {
        if (!ReachSpot)
        {
            ReachSpot = true;
            robot.getGear().stop();
            arm.rotateTo(140, true);
            robot.getGear().backward();
        }
    }

    public void pressed(SensorPort port)
    {
        robot.getGear().stop();
        robot.exit();
    }

    public void released(SensorPort port)
    {
    }

    public void buttonPressed(Button b)
    {
        robot.exit();
    }

    public void buttonReleased(Button b)
    {
    }

    public static void main(String[] args)
    {

        new ReMove();
    }
}
